package com.bana.fvs.app.mvp.presenter;

import android.app.Activity;

import com.bana.fvs.app.module.tab2.entity.ControlResultBean;
import com.bana.fvs.app.module.tab2.tab2Detail.entity.EquipListItemBean;
import com.bana.fvs.app.mvp.contract.EquipListContract;
import com.bana.fvs.app.mvp.model.EquipListModel;
import com.wei.commonlibrary.net.CommException;
import com.wei.commonlibrary.net.MyDefaultCallback;

import java.util.List;

/**
 * Author : yanftch
 * Date : 2018/3/2
 * Time : 22:42
 * Desc :
 */

public class EquipListPresenter extends EquipListContract.AbsEquipListPresenter {
    private static final String DEBUG_TAG = "debug_EquipListPresenter";

    @Override
    public void http_controlLamp(Activity activity, String token, String sbbm, String kzcz) {
                mModel.http_controlLamp(activity,token,sbbm,kzcz).callback(new MyDefaultCallback<ControlResultBean>(activity,true) {
                    @Override
                    public void onError(CommException e) {
                        if (null != getView())
                            getView().onError(e);
                    }

                    @Override
                    public void response(ControlResultBean bean) {
                    if (null != getView()){
                        getView().onControllerResult(bean);
                    }
                    }
                });
    }

    @Override
    public void http_controlController(Activity activity, String token, String sbbm, String kzcz) {
        mModel.http_controlController(activity, token, sbbm, kzcz).callback(new MyDefaultCallback<ControlResultBean>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView())
                    getView().onError(e);
            }

            @Override
            public void response(ControlResultBean bean) {
                if (null != getView()) {
                    getView().onControllerResult(bean);
                }
            }
        });
    }

    @Override
    public void http_controlVisibility(Activity activity, String token, String sbbm, String kzcz) {
        mModel.http_controlVisibility(activity, token, sbbm, kzcz).callback(new MyDefaultCallback<ControlResultBean>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView())
                    getView().onError(e);
            }

            @Override
            public void response(ControlResultBean bean) {
                if (null != getView()) {
                    getView().onVisibilityResult(bean);
                }
            }
        });
    }

    @Override
    public void http_getEquipList(Activity activity, String token, String sblx, String sbzt, String wqbm, int pagenum) {
        mModel.http_getEquipList(activity, token, sblx, sbzt, wqbm, pagenum).callback(new MyDefaultCallback<List<EquipListItemBean>>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView())
                    getView().onError(e);
            }

            @Override
            public void response(List<EquipListItemBean> equipListItemBeans) {
                if (null != getView())
                    getView().onResponse(equipListItemBeans);
            }
        });
    }

    @Override
    protected EquipListContract.AbsEquipListModel createModel() {
        return new EquipListModel();
    }
}
